<?php

namespace App\Http\ApiControllers;

use App\Facades\Api;
use App\Http\Resources\LikeCollection;
use App\Models\Order;
use App\Models\Player;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class SupportController extends ApiController
{
    public function index(Player $player): JsonResponse
    {
        $list = $player->supports()
            ->latest()
            ->paginate();

        return $this->success(new LikeCollection($list));
    }

    public function store(Request $request, Player $player): JsonResponse
    {
        $amount = $request->amount;

        $order = Order::create([
            'application_id' => 1,
            'season_id' => $player->season_id,
            'chapter_id' => $player->chapter_id,
            'player_id' => $player->id,
            'user_id' => Api::id(),
            'wechat_id' => $player->getWechatId(),
            'payment_id' => $player->getPaymentId(),
            'amount' => $amount,
        ]);

        return $this->orderResponse($order, $player);
    }
}
